#include<iostream>
#include<vector>
using namespace std;
class Solution {
public:
    vector<vector<int>> generateMatrix(int con) {
        vector<vector<int>> ret(con, vector<int>(con));
        int l = 0, r = con - 1, u = 0, d = con - 1;
        int n = 0;
        while (l < r && u < d) {
            for (int i = l; i < r; i++) ret[u][i] = ++n;
            for (int i = u; i < d; i++) ret[i][r] = ++n;
            for (int i = r; i > l; i--)ret[d][i] = ++n;
            for (int i = d; i > u; i--)ret[i][l] = ++n;
            r--, l++, u++, d--;
        }
        if (r == l && u == d)ret[u][l] = ++n;
        return ret;
    }
};